package com.senjoeson.abilityservice.action;



import com.senjoeson.abilityservice.service.AutoAccessibilityService;
import com.senjoeson.abilityservice.ControlPanel;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @USER senjoeson
 * @DATE 2021/1/30 5:14 下午
 * @Desc 行为管理器
 **/
public class ActionManager implements IActionManager {

    public static ActionManager actionManager;

    public ConcurrentHashMap<String, AbilityAction> actions = new ConcurrentHashMap<>();
    private AutoAccessibilityService autoAccessibilityService;

    public static ActionManager getInstance() {
        if (actionManager == null) {
            synchronized (ControlPanel.class) {
                if (actionManager == null) {
                    actionManager = new ActionManager();
                }
            }
        }
        return actionManager;
    }


    @Override
    public void register(AbilityAction action) {
        actions.putIfAbsent(action.getClass().getSimpleName(), action);
    }

    @Override
    public void unRegister(AbilityAction action) {
        actions.remove(action.getClass().getSimpleName());
    }

    @Override
    public SystemAction getSysAction() {
        return new SystemActionImpl(autoAccessibilityService);
    }

    @Override
    public UserAction getUserAction() {
        return new ClickUserActionImpl(autoAccessibilityService);
    }

    @Override
    public void init(AutoAccessibilityService autoAccessibilityService) {
        this.autoAccessibilityService = autoAccessibilityService;
    }


}
